from django.views import View
# 导入返回响应
from SaaSDevelTool.data_return_response import create_response
# 导入错误信息装饰器
from SaaSDevelTool.data_return_response import error_message_detection
# 导入数据库连接
from SaaSDevelTool.data_mysql_data import db

"""展示模型"""


class SaaSDevelModelClassQuery(View):
    @error_message_detection
    def get(self, request):
        """展示模型信息"""
        # 定义sql语句获取模型信息
        query_sum_model_table_sql = """
        SELECT model_id,model_name,model_images FROM db_saas_center.sum_model_table;"""
        # 获取到对应的值
        query_sum_model_table_data = db.findAll(query_sum_model_table_sql)

        # 返回对应的数据
        return create_response(code=200, msg="", data=query_sum_model_table_data)


class SaaSDevelPackageModelQuery(View):
    @error_message_detection
    def get(self, request):
        model_id = request.GET.get("model_id")
        # 获取model_id下的子信息
        query_sum_package_table_sql = """
        SELECT package_id,package_name,package_remark FROM db_saas_center.sum_package_table WHERE model_id = '%s'""" % int(
            model_id)

        # 获取到对应的值
        query_sum_package_table_data = db.findAll(query_sum_package_table_sql)

        # 返回对应的数据
        return create_response(code=200, msg="", data=query_sum_package_table_data)
